<p>Compression is implemented by the <code>DEFLATE</code>
<a href="../filter.html">filter</a>. The following directive
will enable compression for documents in the container where it
is placed:</p>
<div class="example"><p><code>
SetOutputFilter DEFLATE
</code></p></div>
<p>Some popular browsers cannot handle compression of all content
so you may want to set the <code>gzip-only-text/html</code> note to
<code>1</code> to only allow html files to be compressed (see
below). If you set this to <em>anything but <code>1</code></em> it
will be ignored.</p>
<p>If you want to restrict the compression to particular MIME types
in general, you may use the <code class="directive"><a href="../mod/core.html#addoutputfilterbytype">AddOutputFilterByType</a></code> directive. Here is an example of
enabling compression only for the html files of the Apache
documentation:</p>
<div class="example"><p><code>
<Directory "/your-server-root/manual"><br />
<span class="indent">
AddOutputFilterByType DEFLATE text/html<br />
</span>
</Directory>
</code></p></div>
<p>For browsers that have problems even with compression of all file
types, use the <code class="directive"><a href="../mod/mod_setenvif.html#browsermatch">BrowserMatch</a></code> directive to set the <code>no-gzip</code>
note for that particular browser so that no compression will be
performed. You may combine <code>no-gzip</code> with <code>gzip-only-text/html</code> to get the best results. In that case
the former overrides the latter. Take a look at the following
excerpt from the <a href="#recommended">configuration example</a>
defined in the section above:</p>
<div class="example"><p><code>
BrowserMatch ^Mozilla/4 gzip-only-text/html<br />
BrowserMatch ^Mozilla/4\.0[678] no-gzip<br />
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</code></p></div>
<p>At first we probe for a <code>User-Agent</code> string that
indicates a Netscape Navigator version of 4.x. These versions
cannot handle compression of types other than
<code>text/html</code>. The versions 4.06, 4.07 and 4.08 also
have problems with decompressing html files. Thus, we completely
turn off the deflate filter for them.</p>
<p>The third <code class="directive"><a href="../mod/mod_setenvif.html#browsermatch">BrowserMatch</a></code>
directive fixes the guessed identity of the user agent, because
the Microsoft Internet Explorer identifies itself also as "Mozilla/4"
but is actually able to handle requested compression. Therefore we
match against the additional string "MSIE" (<code>\b</code> means
"word boundary") in the <code>User-Agent</code> Header and turn off
the restrictions defined before.</p>
<div class="note"><h3>Note</h3>
The <code>DEFLATE</code> filter is always inserted after RESOURCE
filters like PHP or SSI. It never touches internal subrequests.
</div>
<div class="note"><h3>Note</h3>
There is a environment variable <code>force-gzip</code>,
set via <code class="directive"><a href="../mod/core.html#setenv">SetEnv</a></code>, which
will ignore the accept-encoding setting of your browser and will
<p>The <code class="module"><a href="../mod/mod_deflate.html">mod_deflate</a></code> module also provides a filter for
inflating/uncompressing a gzip compressed response body. In order to activate
this feature you have to insert the <code>INFLATE</code> filter into
the outputfilter chain using <code class="directive"><a href="../mod/core.html#setoutputfilter">SetOutputFilter</a></code> or <code class="directive"><a href="../mod/mod_mime.html#addoutputfilter">AddOutputFilter</a></code>, for example:</p>
<div class="example"><p><code>
<Location /dav-area><br />
<span class="indent">
ProxyPass http://example.com/<br />
SetOutputFilter INFLATE<br />
</span>
</Location>
</code></p></div>
<p>This Example will uncompress gzip'ed output from example.com, so other
<p>The <code class="module"><a href="../mod/mod_deflate.html">mod_deflate</a></code> module also provides a filter for
decompressing a gzip compressed request body . In order to activate
this feature you have to insert the <code>DEFLATE</code> filter into
the input filter chain using <code class="directive"><a href="../mod/core.html#setinputfilter">SetInputFilter</a></code> or <code class="directive"><a href="../mod/mod_mime.html#addinputfilter">AddInputFilter</a></code>, for example:</p>
<div class="example"><p><code>
<Location /dav-area><br />
<span class="indent">
SetInputFilter DEFLATE<br />
</span>
</Location>
</code></p></div>
<p>Now if a request contains a <code>Content-Encoding:
gzip</code> header, the body will be automatically decompressed.
Few browsers have the ability to gzip request bodies. However,
some special applications actually do support request
compression, for instance some <a href="http://www.webdav.org">WebDAV</a> clients.</p>
<div class="warning"><h3>Note on Content-Length</h3>
<p>If you evaluate the request body yourself, <em>don't trust
the <code>Content-Length</code> header!</em>
The Content-Length header reflects the length of the
incoming data from the client and <em>not</em> the byte count of
<p>The <code class="directive">DeflateWindowSize</code> directive specifies the
zlib compression window size (a value between 1 and 15). Generally, the
higher the window size, the higher can the compression ratio be expected.</p>
</div>
</div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="../en/mod/mod_deflate.html" title="English"> en </a> |
<a href="../ja/mod/mod_deflate.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
<a href="../ko/mod/mod_deflate.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p>
</div><div id="footer">
<p class="apache">Copyright 1995-2006 The Apache Software Foundation or its licensors, as applicable.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>